<?php
session_cache_expire(999999999);
if (!isset($_SESSION)) {
    session_start();
}

$lang = $_SESSION['lang'];
if (empty($lang) || $lang == "EN") {
    include "../../value/value_en.php";
} else if ($lang == "VN") {
    include "../../value/value_vn.php";
} else {
    include "../../value/value_kr.php";
}
include '../../operations/connection.php';
include '../../content-accountant/invoicetax.php';
$tonggiacungcap = 0;
$tongthue = 0;
$tongtien = 0;
$loi = '';

$_SESSION['invoice_arr'] = array();
if (isset($_REQUEST['type'])) {
    if ($_REQUEST['type'] == "del") {
        if (isset($_REQUEST['id'])) {
            try {
                $sql = "delete from or_order_tax where or_order_tax.orderid=" . $_REQUEST['id'];
                mysql_query($sql);
                $loi = "l_xoathanhcong";
            } catch (exception $e) {
                $loi = $e->getMessage();
            }
        }
    } 
}
$typesearch=2;
if(isset($_REQUEST['typesearch']))
$typesearch=$_REQUEST['typesearch'];
if ($typesearch == 0) {
    $l_thoigiangiaodich = $l_thoigiangiaodich0;
}
if ($typesearch == 1) {
    $l_thoigiangiaodich = $l_thoigiangiaodich1;
}

if ($typesearch == 2) {
    $l_thoigiangiaodich = $l_thoigiangiaodich0.'/'.$l_thoigiangiaodich1;
}
$cusname1="";
if(isset($_REQUEST['cusname']))
$cusname1=$_REQUEST['cusname'];



$sql="SELECT or_order_tax.* 
from or_order_tax 
where month(or_order_tax.order_time_payment)='" . $_REQUEST['thang'] . "' 
		and year(or_order_tax.order_time_payment)='" . $_REQUEST['nam'] . "' "; 
if($typesearch!=2)
$sql.=" and or_order_tax.is_status='" . $typesearch . "' ";
$sql.=" and or_order_tax.order_cusname LIKE '%".$cusname1."%'
ORDER BY or_order_tax.is_status,or_order_tax.order_cusname,or_order_tax.order_time_transaction,or_order_tax.order_content;";
$sqlinvoice = mysql_query($sql);
$mang1=array();
$mang2=array();
 while ($r = mysql_fetch_array($sqlinvoice)) {
 	$ktdate = getdate(strtotime($r[order_time]));
 	if($r['is_status']==0)
 		$mang1[$r[order_cusname].'-'.$r['is_status']][]=array($r[orderid], $r[order_time],$ktdate[mon], $ktdate[mday], $ktdate[year], $r[order_cusname], $r[order_content], $r[order_quantity], $r[order_supply_rice], $r[order_tax], $r[order_total], $r[order_time_transaction], $r[order_time_payment], $r[is_status], $r[user_create], $r[date_create], $r['order_memo'], $r['status']);
 	else 
 		$mang2[$r[order_cusname].'-'.$r['is_status']][]=array($r[orderid], $r[order_time],$ktdate[mon], $ktdate[mday], $ktdate[year], $r[order_cusname], $r[order_content], $r[order_quantity], $r[order_supply_rice], $r[order_tax], $r[order_total], $r[order_time_transaction], $r[order_time_payment], $r[is_status], $r[user_create], $r[date_create], $r['order_memo'], $r['status']);
}?>
<table cellpadding="0" cellspacing="1" width="100%" border="0" class="ftable ">
                <tr >
                    <th style="width:10px"></th>
                    <th style="width:10px"><?= $l_no ?></th>
                    <th style="width:30px"><?= $l_month ?></th>
                    <th style="width:30px"><?= $l_days ?></th>
                    <th style="width:220px"><?= $l_customer ?></th>
                    <th style="width:30%"><?= $l_product_item ?></th>
                    <th style="width:60px"><?=$l_type_payment ?></th>
                    <th style="width:50px;display: none;"><?= $l_quantity ?></th>
                    <th style="width:90px"><?= $l_Supply_price ?></th>
                    <th style="width:90px"><?= $l_vat ?></th>
                    <th style="width:90px"><?= $l_amount ?></th>
                    <th style="width:90px"><?= $l_thoigiangiaodich ?></th> 
                    <th style="width:90px"><?= $l_payment ?></th> 
                    <th style="width:10%"><?= $l_memo ?></th>
                </tr>
                
                <?php 
                $vitri=0;
                $tonggiacungcap1 = 0;
                $tongthue1 = 0;
                $tongtien1 = 0;
                if(count($mang1)>0){
                foreach ($mang1 as $value =>$giatri){
                	$soluonggiaodich = 0;
                    $tonggiacungcap = 0;
                    $tongthue = 0;
                    $tongtien = 0;
                   	
                	
					for($i=0;$i<count($giatri);$i++){
					$vitri++;
                ?>
                	
                	 <tr style="padding:3px;">
                            <td>
                                <img onclick="delOneRow(<?=$giatri[$i][0]?>);" src="images/del.png" style="width:20px;height:20px;cursor:pointer;" title="<?php echo $l_delete; ?>" />
                            </td>
                            <td style="padding: 5px;cursor:pointer;" ><p style="width: 20px"><?= $vitri ?></p></td>
                            <td style="cursor:pointer;" ><p style="width: 20px"><?= $giatri[$i][2] ?></p></td>
                            <td style="cursor:pointer;" ><p style="width: 20px"><?= $giatri[$i][3] ?></p></td>
                            <td style="cursor:pointer;text-align:left;padding-left:3px;" ><p style="width: 200px"><?php echo $giatri[$i][5] ?></p></td>
                            <td style="cursor:pointer;text-align:left;padding-left:3px;" ><p style="min-width: 200px"><?= $giatri[$i][6] ?></p></td>
                            <td style="cursor:pointer;" ><p style="width: 60px"><?php if($giatri[$i][13]==0) echo $l_hdthu; else echo $l_hdchi;?></p></td>
                            <td style="display: none;cursor:pointer;" ><p style="width: 30px"><?= number_format($inobject->order_quantity) ?></p></td>
                            <td style="cursor:pointer;text-align:right;padding-right:3px;" ><p style="width: 90px"><?= number_format($giatri[$i][8]) ?></p></td>
                            <td style="cursor:pointer;text-align:right;padding-right:3px;" ><p style="width: 90px"><?= number_format($giatri[$i][9]) ?></p></td>
                            <td style="cursor:pointer;text-align:right;padding-right:3px;" ><p style="width: 90px"><?= number_format($giatri[$i][10]) ?></p></td>
                            <td style="cursor:pointer;" >
                                <p style="width: 80px"> <?php
							                if ($giatri[$i][11]== "0000-00-00")
							                    echo "";
							                else
							                    echo $giatri[$i][11];
                        					?>
                                </p>
                            </td>
                            
                            <td style="cursor:pointer;" >
                                <p style="width: 80px"> <?php
							                if ($giatri[$i][12]== "0000-00-00")
							                    echo "";
							                else
							                    echo $giatri[$i][12];
                        					?>
                                </p>
                            </td>
                            <td style="cursor:pointer;" ><p style="min-width: 120px"><?= $giatri[$i][16] ?></p></td>

		        <?php
		        	$soluonggiaodich++;
			        $tonggiacungcap +=$giatri[$i][8];
			        $tongthue +=$giatri[$i][9];
			        $tongtien +=$giatri[$i][10]; 
			        $tonggiacungcap1 +=$giatri[$i][8];
			        $tongthue1 +=$giatri[$i][9];
			        $tongtien1 +=$giatri[$i][10]; 
		        ?>
        	</tr>
               
		        <?php }?>
               
                <tr class="coltr2" style="height:30px;font-weight:bold;">
                    <td colspan="6"><!--<?php echo $l_all . '-' . $l_month; ?> : <font color="red"><?php echo $_SESSION['months'] ?></font>  -->  <?php echo $l_co; ?>  <font color="blue"><?php echo number_format($soluonggiaodich); ?></font> <?php echo $l_giaodich; ?></td>
                    <td></td>
                    <td style="display: none;"></td>
                    <td style="text-align:right;padding-right:3px;"><?php echo number_format($tonggiacungcap); ?></td>
                    <td style="text-align:right;padding-right:3px;"><?php echo number_format($tongthue); ?></td>
                    <td style="text-align:right;padding-right:3px;"><?php echo number_format($tongtien); ?></td>
                    <td colspan="3"></td>
                </tr>  
               <?php 
                }
                ?>
                <tr class="coltr2" style="height:30px;font-weight:bold;">
                    <td colspan="6"><?php echo $l_hdthu; ?></td>
                    <td></td>
                    <td style="display: none;"></td>
                    <td style="text-align:right;padding-right:3px;"><?php echo number_format($tonggiacungcap1); ?></td>
                    <td style="text-align:right;padding-right:3px;"><?php echo number_format($tongthue1); ?></td>
                    <td style="text-align:right;padding-right:3px;"><?php echo number_format($tongtien1); ?></td>
                    <td colspan="3"></td>
                </tr>
                <?php }
                $tonggiacungcap1 = 0;
                $tongthue1 = 0;
                $tongtien1 = 0;
                if(count($mang2)>0){
                foreach ($mang2 as $value =>$giatri){
                	$soluonggiaodich = 0;
                    $tonggiacungcap = 0;
                    $tongthue = 0;
                    $tongtien = 0;
                   	
                	
					for($i=0;$i<count($giatri);$i++){
					$vitri++;
                ?>
                	
                	 <tr style="padding:3px;">
                            <td>
                                <img onclick="delOneRow(<?=$giatri[$i][0]?>);" src="images/del.png" style="width:20px;height:20px;cursor:pointer;" title="<?php echo $l_delete; ?>" />
                            </td>
                            <td style="padding: 5px;cursor:pointer;" ><p style="width: 20px"><?= $vitri ?></p></td>
                            <td style="cursor:pointer;" ><p style="width: 20px"><?= $giatri[$i][2] ?></p></td>
                            <td style="cursor:pointer;" ><p style="width: 20px"><?= $giatri[$i][3] ?></p></td>
                            <td style="cursor:pointer;text-align:left;padding-left:3px;" ><p style="width: 200px"><?php echo $giatri[$i][5] ?></p></td>
                            <td style="cursor:pointer;text-align:left;padding-left:3px;" ><p style="min-width: 200px"><?= $giatri[$i][6] ?></p></td>
                            <td style="cursor:pointer;" ><p style="width: 60px"><?php if($giatri[$i][13]==0) echo $l_hdthu; else echo $l_hdchi;?></p></td>
                            <td style="display: none;cursor:pointer;" ><p style="width: 30px"><?= number_format($inobject->order_quantity) ?></p></td>
                            <td style="cursor:pointer;text-align:right;padding-right:3px;" ><p style="width: 90px"><?= number_format($giatri[$i][8]) ?></p></td>
                            <td style="cursor:pointer;text-align:right;padding-right:3px;" ><p style="width: 90px"><?= number_format($giatri[$i][9]) ?></p></td>
                            <td style="cursor:pointer;text-align:right;padding-right:3px;" ><p style="width: 90px"><?= number_format($giatri[$i][10]) ?></p></td>
                            <td style="cursor:pointer;" >
                                <p style="width: 80px"> <?php
							                if ($giatri[$i][11]== "0000-00-00")
							                    echo "";
							                else
							                    echo $giatri[$i][11];
                        					?>
                                </p>
                            </td>
                            
                            <td style="cursor:pointer;" >
                                <p style="width: 80px"> <?php
							                if ($giatri[$i][12]== "0000-00-00")
							                    echo "";
							                else
							                    echo $giatri[$i][12];
                        					?>
                                </p>
                            </td>
                            <td style="cursor:pointer;" ><p style="min-width: 120px"><?= $giatri[$i][16] ?></p></td>

		        <?php
		        	$soluonggiaodich++;
			        $tonggiacungcap +=$giatri[$i][8];
			        $tongthue +=$giatri[$i][9];
			        $tongtien +=$giatri[$i][10]; 
			        $tonggiacungcap1 +=$giatri[$i][8];
			        $tongthue1 +=$giatri[$i][9];
			        $tongtien1 +=$giatri[$i][10]; 
		        ?>
        	</tr>
               
		        <?php }?>
               
                <tr class="coltr2" style="height:30px;font-weight:bold;">
                    <td colspan="6"><!--<?php echo $l_all . '-' . $l_month; ?> : <font color="red"><?php echo $_SESSION['months'] ?></font>  -->  <?php echo $l_co; ?>  <font color="blue"><?php echo number_format($soluonggiaodich); ?></font> <?php echo $l_giaodich; ?></td>
                    <td></td>
                    <td style="display: none;"></td>
                    <td style="text-align:right;padding-right:3px;"><?php echo number_format($tonggiacungcap); ?></td>
                    <td style="text-align:right;padding-right:3px;"><?php echo number_format($tongthue); ?></td>
                    <td style="text-align:right;padding-right:3px;"><?php echo number_format($tongtien); ?></td>
                    <td colspan="3"></td>
                </tr>  
               <?php 
                }
                ?>
                <tr class="coltr2" style="height:30px;font-weight:bold;">
                    <td colspan="6"><?php echo $l_hdchi; ?></td>
                    <td></td>
                    <td style="display: none;"></td>
                    <td style="text-align:right;padding-right:3px;"><?php echo number_format($tonggiacungcap1); ?></td>
                    <td style="text-align:right;padding-right:3px;"><?php echo number_format($tongthue1); ?></td>
                    <td style="text-align:right;padding-right:3px;"><?php echo number_format($tongtien1); ?></td>
                    <td colspan="3"></td>
                </tr>
                <?php }?>
          </table>
<input type="hidden" value="<?= $loi ?>" id="convoi" /> 
<?php mysql_close($connection); ?>